package com.ruike.alisurface.ui;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ruike.alisurface.BuildConfig;
import com.ruike.alisurface.R;
import com.ruike.alisurface.base.BaseAty;
import com.ruike.alisurface.bean.QualificatonBean;
import com.ruike.alisurface.https.ShopApiHttp;
import com.ruike.alisurface.utils.GsonUtils;
import com.voodoo.lib_http.ApiListener;
import com.voodoo.lib_utils.imageLoader.GlideImageLoader;

import org.json.JSONObject;

import butterknife.BindView;

public class Qualification_Aty extends BaseAty {

    @BindView(R.id.to_back)
    ImageView toBack;
    @BindView(R.id.to_times)
    TextView toTimes;
    @BindView(R.id.qu_contact_person)
    TextView quContactPerson;
    @BindView(R.id.qu_verstion)
    TextView quVerstion;
    @BindView(R.id.qu_license_img)
    ImageView quLicenseImg;
    @BindView(R.id.qu_permit_img)
    ImageView quPermitImg;
    @BindView(R.id.qu_record_certificate_img)
    ImageView quRecordCertificateImg;

    @Override
    protected int getLayoutResId() {
        return R.layout.app_qualification;
    }

    @Override
    protected void initViews() {
        initTitleBar(false);
        startCountdownTimer(120, toTimes, ShopMain_Aty.class);
        toBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startCountdownTimer(0, toTimes, ShopMain_Aty.class);
            }
        });
    }

    QualificatonBean.DataBean dataBean;

    @Override
    protected void initData() {
        showProgressDialog("加载数据中，请等待...");
        ShopApiHttp.get_qualification_details(new ApiListener() {
            @Override
            public void onRequestStart(String requestUrl, int requestId) {

            }

            @Override
            public void onRequestComplete(String requestUrl, int requestId) {
                removeProgressDialog();
            }

            @Override
            public void onSuccess(String requestUrl, JSONObject requestJson, int requestId) {
                QualificatonBean qualificatonBean = GsonUtils.fromJson(requestJson.toString(), QualificatonBean.class);
                dataBean = qualificatonBean.getData();
                setDataBean();

            }

            @Override
            public void onError(String requestUrl, String errorMsg, String resultData, int requestId) {

            }
        });

    }


    public void setDataBean() {
        quVerstion.setText(BuildConfig.VERSION_NAME);
        if (dataBean != null) {
            quContactPerson.setText(dataBean.getBusiness_contacts() == null ? "" : dataBean.getBusiness_contacts());
            GlideImageLoader.getInstance().loadImage(this, dataBean.getCertificate(), quLicenseImg);
            GlideImageLoader.getInstance().loadImage(this, dataBean.getMedical_instrument_certificate(), quPermitImg);
            GlideImageLoader.getInstance().loadImage(this, dataBean.getSecond_certificate(), quRecordCertificateImg);
        }
    }
}
